package com.yxs.shopping.controller;


import com.yxs.test.feign.TestFeignClient;
import com.yxs.test.model.dto.UserResult;
import com.yxs.test.model.dto.UserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("shopping/test")
public class TestController {
    @Autowired
    private TestFeignClient testFeignClient;

    /**
     * get请求的query参数 到 对象，由于springMVC是支持GET方法直接绑定POJO的
     * @param userDto
     * @return
     */
    @GetMapping("helloTestFeign")
//    @HystrixCommand(fallbackMethod = "fallback")
    public UserResult helloTestFeign(UserDto userDto){
//        int i = 1/0;
        return testFeignClient.test(userDto);
    }

    /**
     * get请求的query参数 到 map ，需要 @RequestParam
     * @param map
     * @return
     */
    @GetMapping("testMapForGet")
    public UserResult testMapForGet(@RequestParam Map<String,Object> map){
        return testFeignClient.testMap(map);
    }
    public UserResult fallback() {
        UserResult result = new UserResult();
        result.setUserName("错误了");
        return result;
    }
}
